<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Yy</title>
</head>

<body>
    <input type="text">
    <button>添加列表</button>
    <ul>
        <li>香蕉</li>
        <li>苹果</li>
        <li>鸭梨</li>
    </ul>
    <script>
        // 1. 实现一个水果列表的添加与删除功能
        let ul = document.querySelector("ul");
        let btn = document.querySelector("button");
        let inp = document.querySelector("input");
        btn.onclick = function() {
            let value = inp.value;
            let li = document.createElement("li");
            let txt = document.createTextNode(value);
            ul.appendChild(li);
            li.appendChild(txt);
        }

        ul.onclick = function(e) {
            ul.removeChild(e.target)
        }
    </script>




</body>

</html>